#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
检查排列5模型文件结构
"""

import torch
import os

def check_model_structure(model_path):
    """检查模型文件结构"""
    if not os.path.exists(model_path):
        print(f" 模型文件不存在: {model_path}")
        return
    
    print(f" 检查模型文件: {model_path}")
    
    try:
        # 加载模型检查点
        checkpoint = torch.load(model_path, map_location='cpu')
        print(f"✅ 成功加载模型文件")
        print(f"📋 检查点键值: {list(checkpoint.keys())}")
        
        # 检查模型状态字典
        if 'lstm_model' in checkpoint:
            print(f"📋 LSTM模型状态字典键值 (前10个): {list(checkpoint['lstm_model'].keys())[:10]}")
            print(f" LSTM模型状态字典大小: {len(checkpoint['lstm_model'])}")
        elif 'model' in checkpoint:
            print(f"📋 模型状态字典键值 (前10个): {list(checkpoint['model'].keys())[:10]}")
            print(f" 模型状态字典大小: {len(checkpoint['model'])}")
        else:
            print("⚠️ 未找到模型状态字典")
            
        # 检查集成配置
        if 'ensemble_config' in checkpoint:
            print(f"📋 集成配置: {checkpoint['ensemble_config']}")
            
    except Exception as e:
        print(f" 加载模型文件失败: {e}")
        import traceback
        print(traceback.format_exc())

if __name__ == "__main__":
    import sys
    project_root = os.path.dirname(os.path.abspath(__file__))
    
    # 检查所有排列5模型文件
    model_files = [
        "plw_model.pth",
        "plw_lstm_model.pth",
        "plw_transformer_model.pth",
        "plw_sequence_lstm_model.pth"
    ]
    
    for model_file in model_files:
        model_path = os.path.join(project_root, 'scripts', 'plw', model_file)
        check_model_structure(model_path)
        print("-" * 60)